﻿using Dapper.Contrib.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PSDLib.Models
{
    public enum DeviceRebootType : int
    {
        常规重启 = 0,
        无法连接服务器重启 = 1,
        丢失服务器通讯重启 = 2,
    }
    public enum DownloadTaskCreateType : int
    {
        //任务类型（0：常规Routine，1：谈话Talk，2：放风Relieve，3：进点，4：离点，5：换房间，6：外出谈话去程，7：外出谈话回程，8：自定义时段，9：摄像机SD卡）

        常规Routine = 0,
        谈话Talk = 1,
        放风Relieve = 2,
        进点 = 3,
        离点 = 4,
        换房间 = 5,
        外出谈话去程 = 6,
        外出谈话回程 = 7,
        自定义时段 = 8,
        摄像机SD卡 = 9,
    }

    public enum DownloadTaskRouteType : int
    {
        //路径类型（0：对象进点，1：对象换房间，2：对象放风，3：对象离点，4：外出谈话去程，5：外出谈话回程）
        对象进点 = 0,
        对象换房间 = 1,
        对象放风 = 2,
        对象离点 = 3,
        外出谈话 = 4,
    }

    public enum DownloadFileState : int
    {
        /// <summary>
        /// 等待下载
        /// </summary>
        Waiting = -1,
        /// <summary>
        /// 正在下载
        /// </summary>
        Downloading = 0,
        /// <summary>
        /// 下载完成
        /// </summary>
        Success = 1,
        /// <summary>
        /// 下载失败
        /// </summary>
        Fail = 2,
        /// <summary>
        /// 下载成功并结束任务
        /// </summary>
        SuccessAndFinish = 3
    }

    public class dl_task_start
    {
        public string deviceId { get; set; }
        public string roomNum { get; set; }
        public DateTime startTime { get; set; }
        public DateTime? endTime { get; set; }
        public int extendTime { get; set; }
        public int state { get; set; }
        public int taskType { get; set; } = 0;
        public int createType { get; set; } = 0;
        public int currentCase { get; set; } = 1;
    }

    public class dl_task
    {
        public string id { get; set; }
        public string task_name { get; set; }
        public string entery_id { get; set; }
        public string room_id { get; set; }
        public string room_num { get; set; }
        public int download_state { get; set; }
        public int file_count { get; set; }
        public int error_count { get; set; }
        public string download_device_id { get; set; }
        public DateTime start_time { get; set; }
        public DateTime? end_time { get; set; }
        /// <summary>
        /// 任务类型（0：常规Routine，1：谈话Talk，2：放风Relieve，3：进点，4：离点，5：换房间，6：外出谈话去程，7：外出谈话回程）
        /// </summary>
        public int task_type { get; set; }
        public string object_id { get; set; }
        public DateTime? create_time { get; set; }
        /// <summary>
        /// 创建方式（0：管理端创建，1：行为记录创建）
        /// </summary>
        public int create_type { get; set; }
        public string route_id { get; set; }
    }

    public enum DownloadTaskSate : int
    {
        暂停下载 = 0,
        开始下载 = 1,
        结束下载 = 2,
    }


    public class dl_task_channel
    {
        public string id { get; set; }
        public string dl_task_id { get; set; }
        public string room_num { get; set; }
        public string channel_id { get; set; }
        public string channel_name { get; set; }
        public int stream_type { get; set; }
        public DateTime start_time { get; set; }
        public DateTime? end_time { get; set; }
        public DateTime? last_time { get; set; }
        public int file_count { get; set; }
        public int error_count { get; set; }
        public int download_state { get; set; }
        public string last_file_name { get; set; }
        public string current_file_name { get; set; }

        public string server_id { get; set; }

    }

    public enum DownloadChanelState : int
    {
        未开始 = 0,
        正在下载 = 1,
        已结束 = 2,
    }

    public class dl_files
    {

        public string id { get; set; }
        public string dl_device_id { get; set; }
        public string dl_task_id { get; set; }
        public string dl_task_channel_id { get; set; }
        public string room_num { get; set; }
        public string channel_id { get; set; }
        public string channel_name { get; set; }
        public DateTime video_start_time { get; set; }
        public DateTime video_end_time { get; set; }
        public string file_name { get; set; }
        public Int64 file_size { get; set; }
        public int stream_type { get; set; }
        public string file_path { get; set; }
        public int dl_progress { get; set; }
        public DateTime? dl_start_time { get; set; }
        public DateTime? dl_end_time { get; set; }
        public Int64 dl_speed { get; set; }
        public int state { get; set; }
        public string error_log { get; set; }
    }

    [Table("local_files")]
    public class local_files
    {
        public string dl_id { get; set; }
        public string dl_device_id { get; set; }
        public string dl_task_id { get; set; }
        public string dl_task_channel_id { get; set; }
        public string room_num { get; set; }
        public string channel_id { get; set; }
        public string channel_name { get; set; }
        public DateTime video_start_time { get; set; }
        public DateTime video_end_time { get; set; }
        public string file_name { get; set; }
        public Int64 file_size { get; set; }
        public int stream_type { get; set; }
        public string file_path { get; set; }
        public int dl_progress { get; set; }
        public DateTime? dl_start_time { get; set; }
        public DateTime? dl_end_time { get; set; }
        public Int64 dl_speed { get; set; }
        public int state { get; set; }
        public string error_log { get; set; }

        public dl_files To_dl_file()
        {
            var prop = typeof(local_files).GetProperties().ToList();
            var prop_dl = typeof(dl_files).GetProperties().ToList();
            var file = new dl_files();
            foreach (var p in prop)
            {
                var pro = prop_dl.Where(t => t.Name == p.Name).FirstOrDefault();

                if (pro != null)
                {
                    pro.SetValue(file, p.GetValue(this, null), null);
                }
            }

            file.id = this.dl_id;

            return file;
        }

        public void From_dl_file(dl_files file)
        {
            var prop = typeof(local_files).GetProperties().ToList();
            var prop_dl = typeof(dl_files).GetProperties().ToList();

            foreach (var p in prop_dl)
            {
                var pro = prop.Where(t => t.Name == p.Name).FirstOrDefault();

                if (pro != null)
                {
                    pro.SetValue(this, p.GetValue(file, null), null);
                }
            }

            this.dl_id = file.id;
        }
    }

    public class dl_download_device
    {
        public string id { get; set; }
        public string device_name { get; set; }
        public int device_connect_type { get; set; }
        public string device_ip { get; set; }
        public int device_port { get; set; }
        public string main_storage { get; set; }
        public double main_storage_total { get; set; }
        public double main_storage_free { get; set; }
        public string second_storage { get; set; }
        public double second_storage_total { get; set; }
        public double second_storage_free { get; set; }
        public string current_storage { get; set; }
        public string data_path { get; set; }
        public string log_path { get; set; }
        public int state { get; set; }
        public string dl_server_id { get; set; }
        public int max_download_process { get; set; }
        public double storage_available_percent { get; set; }
        public string device_version { get; set; }
        public string device_key { get; set; }
        public string device_pwd { get; set; }
        public string device_pwd_salt { get; set; }
        public int storage_type { get; set; }
        public int burn_enable { get; set; }
        public int burn_port { get; set; }
        public int recorder_count { get; set; }
        public int online { get; set; }

        public DateTime? online_update_time { get; set; }

        //[JsonIgnore]
        public List<dl_download_device_storage> StorageList { get; set; }

        public List<string> RecorderList { get; set; }
        public dl_download_device()
        {
            StorageList = new List<dl_download_device_storage>();
            RecorderList = new List<string>();
        }
    }

    public class dl_download_device_storage
    {
        public string id { get; set; }
        public string device_id { get; set; }
        public string storage_driver { get; set; }
        public string storage_name { get; set; }
        public int storage_type { get; set; }
        public int storage_group { get; set; }
        public double storage_total_size { get; set; }
        public double storage_free_size { get; set; }
        public int state { get; set; }
    }

    public class dl_server_config
    {
        public string id { get; set; }
        public string storage_server_type { get; set; }
        public string storage_server_ip { get; set; }
        public int storage_server_port { get; set; }
        public string storage_server_user { get; set; }
        public string storage_server_password { get; set; }
        public int stream_type { get; set; }
        public string storage_server_name { get; set; }
        public string file_type { get; set; }

    }

    /// <summary>
    /// 下载通道路线配置实体类
    /// </summary>
    public class dl_route
    {
        #region Properties

        /// <summary>
        /// 主键id
        /// </summary>
        [DisplayName("主键id")]
        public string id { get; set; }

        /// <summary>
        /// 路径名称
        /// </summary>
        [DisplayName("路径名称")]
        public string name { get; set; }

        /// <summary>
        /// 路径类型（0：对象进点离点，1：对象换房间，2：对象放风
        /// </summary>
        [DisplayName("路径类型（0：对象进点，1：对象换房间，2：对象放风，3：对象离点，4：外出谈话去程，5：外出谈话回程）")]
        public int route_type { get; set; }

        /// <summary>
        /// 起点位置id
        /// </summary>
        [DisplayName("起点位置id")]
        public string start_location_id { get; set; }

        /// <summary>
        /// 起点位置名称
        /// </summary>
        [DisplayName("起点位置名称")]
        public string start_location_name { get; set; }

        /// <summary>
        /// 起点位置类型（0：留置间，1：放风区域，2：谈话室）
        /// </summary>
        [DisplayName("起点位置类型（0：留置区域，1：放风区域，2：谈话区域）")]
        public int start_location_type { get; set; }



        /// <summary>
        /// 终点位置id
        /// </summary>
        [DisplayName("终点位置id")]
        public string end_location_id { get; set; }

        /// <summary>
        /// 终点位置名称
        /// </summary>
        [DisplayName("终点位置名称")]
        public string end_location_name { get; set; }

        /// <summary>
        /// 终点位置类型（0：留置间，1：放风区域，2：谈话室）
        /// </summary>
        [DisplayName("起点位置类型（0：留置区域，1：放风区域，2：谈话区域）")]
        public int end_location_type { get; set; }

        #endregion
    }

    /// <summary>
    /// dl_route_channel实体类
    /// </summary>
    public class dl_route_config
    {
        #region Properties

        /// <summary>
        /// 主键id
        /// </summary>
        [DisplayName("主键id")]
        public string id { get; set; }

        /// <summary>
        /// 路线id
        /// </summary>
        [DisplayName("路线id")]
        public string route_id { get; set; }

        /// <summary>
        /// 通道id
        /// </summary>
        [DisplayName("通道id")]
        public string channel_id { get; set; }

        /// <summary>
        /// 通道名称
        /// </summary>
        [DisplayName("通道名称")]
        public string channel_name { get; set; }

        /// <summary>
        /// 下载服务器id
        /// </summary>
        [DisplayName("下载服务器id")]
        public string server_id { get; set; }

        #endregion
    }

    public class dl_route_config_vo : dl_route_config
    {
        public string storage_server_type { get; set; }
        public string storage_server_ip { get; set; }
        public string storage_server_name { get; set; }
    }

    public class dl_camera
    {
        #region Properties

        /// <summary>
        /// 主键id
        /// </summary>
        [DisplayName("主键id")]
        public string id { get; set; }

        /// <summary>
        /// 房间号
        /// </summary>
        [DisplayName("房间号")]
        public string room_num { get; set; }

        /// <summary>
        /// 摄像机名称
        /// </summary>
        [DisplayName("摄像机名称")]
        public string camera_name { get; set; }

        /// <summary>
        /// 摄像机IP
        /// </summary>
        [DisplayName("摄像机IP")]
        public string camera_ip { get; set; }

        /// <summary>
        /// 摄像机登录用户
        /// </summary>
        [DisplayName("摄像机登录用户")]
        public string camera_user { get; set; }

        /// <summary>
        /// 摄像机登录密码
        /// </summary>
        [DisplayName("摄像机登录密码")]
        public string camera_pwd { get; set; }

        /// <summary>
        /// 存储IP
        /// </summary>
        [DisplayName("存储IP")]
        public string storage_ip { get; set; }

        /// <summary>
        /// 存储通道号
        /// </summary>
        [DisplayName("存储通道号")]
        public int channel_id { get; set; }

        #endregion
    }


    /// <summary>
    /// PSD版本信息实体类
    /// </summary>
    public class dl_psd_version
    {
        #region Properties

        /// <summary>
        /// 主键id
        /// </summary>
        [DisplayName("主键id")]
        public string id { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        [DisplayName("版本号")]
        public string psd_version { get; set; }

        /// <summary>
        /// 版本说明
        /// </summary>
        [DisplayName("版本说明")]
        public string description { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [DisplayName("创建时间")]
        public DateTime create_time { get; set; }

        /// <summary>
        /// 下载操作
        /// </summary>
        [DisplayName("下载操作")]
        public string action { get; set; }

        /// <summary>
        /// 发布成功数
        /// </summary>
        [DisplayName("发布成功数")]
        public int update_success { get; set; }

        /// <summary>
        /// 发布失败数
        /// </summary>
        [DisplayName("发布失败数")]
        public int update_fail { get; set; }

        #endregion
    }

    public class dl_psd_version_vo : dl_psd_version
    {
        public int devcie_count { get; set; }
    }

    /// <summary>
    /// PSD版本文件实体类
    /// </summary>
    public class dl_psd_version_file
    {
        #region Properties

        /// <summary>
        /// 主键id
        /// </summary>
        [DisplayName("主键id")]
        public string id { get; set; }

        /// <summary>
        /// 版本
        /// </summary>
        [DisplayName("版本")]
        public string psd_version { get; set; }

        /// <summary>
        /// 文件名
        /// </summary>
        [DisplayName("文件名")]
        public string file_name { get; set; }

        /// <summary>
        /// 文件路径
        /// </summary>
        [DisplayName("文件路径")]
        public string file_path { get; set; }

        /// <summary>
        /// 文件大小
        /// </summary>
        [DisplayName("文件大小")]
        public long file_size { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [DisplayName("创建时间")]
        public DateTime create_time { get; set; }

        /// <summary>
        /// 文件校验SHA值
        /// </summary>
        [DisplayName("文件校验SHA值")]
        public string sign { get; set; }

        #endregion
    }

    public class dl_psd_version_file_vo : dl_psd_version_file
    {
        /// <summary>
        /// 本地文件路径
        /// </summary>
        public string local_path { get; set; }
    }

    /// <summary>
    /// PSD设备版本更新日志实体类
    /// </summary>
    public class dl_psd_version_updatelog
    {
        #region Properties

        /// <summary>
        /// 主键id
        /// </summary>
        [DisplayName("主键id")]
        public string id { get; set; }

        /// <summary>
        /// psd版本号
        /// </summary>
        [DisplayName("psd版本号")]
        public string psd_version { get; set; }

        /// <summary>
        /// 设备id
        /// </summary>
        [DisplayName("设备id")]
        public string device_id { get; set; }

        /// <summary>
        /// 更新状态（0：失败，1：成功）
        /// </summary>
        [DisplayName("更新状态（0:未更新，1：成功，2：失败）")]
        public int? update_state { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        [DisplayName("更新时间")]
        public DateTime? update_time { get; set; }

        #endregion
    }
}
